package com.wu.controller.system;

import com.wu.base.ApiResponse;
import com.wu.base.PageInfoData;
import com.wu.controller.BaseController;
import com.wu.pojo.reqeust.BaseRequest;
import com.wu.pojo.reqeust.CommonIdRequest;
import com.wu.pojo.reqeust.CommonIdStatusRequest;
import com.wu.pojo.reqeust.sys.*;
import com.wu.pojo.response.sys.RoleListResponse;
import com.wu.pojo.response.sys.RoleUserListResponse;
import com.wu.service.sys.SRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author wujilu
 * @since 2020-11-24
 */
@RestController
@Api(tags = "S角色相关接口")
@RequestMapping("/role")
public class SRoleController extends BaseController {

    @Resource
    private SRoleService roleService;

    /**
     * 新增/修改 角色
     */
    @ApiOperation(value = "角色 列表")
    @RequiresPermissions("/role/list")
    @PostMapping(value = "/list")
    public ApiResponse<PageInfoData<RoleListResponse>> listRole(@RequestBody ListRoleRequest request) {
        return roleService.listRole(request);
    }

    @ApiOperation(value = "下拉选择列表")
    @RequiresPermissions("/role/optionList")
    @PostMapping(value = "/optionList")
    public ApiResponse<RoleListResponse> optionList(@RequestBody BaseRequest request) {
        return roleService.optionList(request);
    }

    
    @ApiOperation(value = "新增 角色")
    @RequiresPermissions("/role/save")
    @PostMapping(value = "/save")
    public ApiResponse save(@Validated() @RequestBody SaveRoleRequest request) {
        return roleService.save(request);
    }
    
    @ApiOperation(value = "修改 角色")
    @RequiresPermissions("/role/edit")
    @PostMapping(value = "/edit")
    public ApiResponse edit(@Validated() @RequestBody UpdateRoleRequest request) {
        return roleService.edit(request);
    }

    @ApiOperation(value = "停用/启用")
    @RequiresPermissions("/role/onOrOff")
    @PostMapping(value = "/onOrOff")
    public ApiResponse onOrOff(@Validated() @RequestBody CommonIdStatusRequest request) {
        return roleService.onOrOff(request);
    }

    @ApiOperation(value = "删除 角色")
    @RequiresPermissions("/role/delete")
    @PostMapping(value = "/delete")
    public ApiResponse deleteRole(@Validated() @RequestBody CommonIdRequest request) {
        return roleService.deleteRole(request);
    }

    @ApiOperation(value = "修改角色的权限")
    @RequiresPermissions("/role/editResource")
    @PostMapping(value = "/editResource")
    public ApiResponse editResource(@Validated() @RequestBody RoleResourceEditRequest request) {
        return roleService.editResource(request, getSessionUserId());
    }

    @ApiOperation(value = "根据id查询角色")
    @RequiresPermissions("/role/getById")
    @PostMapping(value = "/getById")
    public ApiResponse<RoleListResponse> getById(@Validated() @RequestBody CommonIdRequest request) {
        return roleService.getById(request);
    }

    @ApiOperation(value = "根据id查询角色下用户列表")
    @RequiresPermissions("/role/roleUserList")
    @PostMapping(value = "/roleUserList")
    public ApiResponse<RoleUserListResponse> roleUserList(@Validated() @RequestBody RoleUserListRequest request) {
        return roleService.roleUserList(request);
    }

}
